clear all

*Set working folders. Please change the global variable "user" to the folder with the replication package
global user "C:\Users\weilingliu1990\Dropbox\Insurance Project\LTCI Replication Package"
global data "$user\Data"
global images "$user\Images"
global drafttab "$user\Tables"

set maxvar  32767


*********************************************
************* PLOT CUMULATIVE DATA **********
*********************************************

//FIGURE 5A
***************************************************
****** 1) graph by election cycle frictions *******
***************************************************

**** FIGURE 4 ****
*********** by election cycles 
use "$data\cumulative_data", clear
replace earned_prem=abs(earned_prem)
collapse (sum) earned_prem incur_claims , by(year match2)

gen profit3=(earned_prem-incur_claims)/1e9

tsset match2 year
by match2 (year): gen cum_profit3=sum(profit3)

drop if match2==0
twoway (connected  cum_profit3 year if match2==1) (connected  cum_profit3 year if match2==-1), graphregion(color(white)) bgcolor(white) legend(label(1 "Low Election Friction") label(2 "High Election Friction")) ylab(0(3)12, nogrid) xtitle(Year) ytitle(Cum. Actual Revenue (bil USD))
graph export "$images\Figure_5A.png", replace


//FIGURE 5B
************************************
****** 2) graph by political party *******
************************************
use "$data\cumulative_data", clear
replace earned_prem=abs(earned_prem)
collapse (sum) earned_prem incur_claims, by(year dem)

gen profit3=earned_prem-incur_claims

tsset dem year
by dem (year): gen cum_profit3=sum(profit3)

drop if dem==0
replace cum_profit3=cum_profit3/1000000000
twoway (connected  cum_profit3 year if dem==1) (connected  cum_profit3 year if dem==-1), graphregion(color(white)) bgcolor(white) legend(label(2 "Republicans") label(1 "Democrats")) ylab(0(3)12, nogrid) xtitle(Year) ytitle(Cumulative Cash Flows (Billions))
graph export "$images\Figure_5B.png", replace



